import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  // 静态路由范围
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/pdf/download',
    component: () => import('@/views/tool/pdf/download'),
    hidden: true
  },
  {
    name: 'Agreement',
    path: '/agreement',
    hidden: true,
    component: () => import('@/views/agreement')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/Dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

/* 
动态路由范围
*/
  // 工具管理
  {
    path: '/tool',
    name: 'Tool',
    component: Layout,
    meta: { title: '工具', icon: 'setting' },
    redirect: '/tool/quillEditor',
    children: [
      {
        path: 'maps',
        component: () => import('@/views/tool/maps'),
        meta: { title: '3D地图' }
      },
      {
        path: 'lineMap',
        component: () => import('@/views/tool/lineMap'),
        meta: { title: '飞线图' }
      },
      {
        path: 'profileMap',
        component: () => import('@/views/tool/profileMap'),
        meta: { title: '分布图' }
      },
      {
        path: 'quillEditor',
        component: () => import('@/views/tool/quillEditor'),
        meta: { title: '富文本编辑器' }
      },
      {
        path: 'slider',
        component: () => import('@/views/tool/slider'),
        meta: { title: 'slider滑块' }
      },
      {
        path: 'rgba',
        component: () => import('@/views/tool/RGBA'),
        meta: { title: 'rgba颜色' }
      },
      {
        path: 'iconSelect',
        component: () => import('@/views/tool/iconSelect'),
        meta: { title: 'icon下拉' }
      },
      {
        path: 'menuTree',
        component: () => import('@/views/tool/menuTree'),
        meta: { title: '菜单树下拉' }
      },
      {
        path: 'dragDialog',
        component: () => import('@/views/tool/DragDialog'),
        meta: { title: '拖拽Dialog' }
      },
      {
        path: 'zip',
        component: () => import('@/views/tool/zip'),
        meta: { title: 'zip下载' }
      },
      {
        path: 'excel',
        component: () => import('@/views/tool/excel'),
        meta: { title: 'excel上传下载' }
      },
      {
        path: 'pdf',
        component: () => import('@/views/tool/pdf'),
        meta: { title: 'pdf下载' }
      },
      {
        path: 'map',
        component: () => import('@/views/tool/map'),
        meta: { title: '百度地图' }
      },
      {
        path: 'GDmap',
        component: () => import('@/views/tool/GDmap'),
        meta: { title: '高德地图' }
      },
      {
        path: 'i18n',
        component: () => import('@/views/tool/international'),
        meta: { title: '国际化' }
      },
      {
        path: 'grey',
        component: () => import('@/views/tool/grey'),
        meta: { title: '网站变灰' }
      },
      {
        path: 'drawer',
        component: () => import('@/views/tool/Drawer'),
        meta: { title: '抽屉' }
      },
      {
        path: 'carousel',
        component: () => import('@/views/tool/Carousel'),
        meta: { title: '走马灯' }
      },
      {
        path: 'test',
        component: () => import('@/views/tool/test'),
        meta: { title: '练习测试' }
      }
    ]
  },
   // echarts系列
   {
    path: '/dataAnalysis',
    name: 'dataAnalysis',
    component: Layout,
    redirect: '/dataAnalysis/production',
    meta: { title: 'echarts系列', icon: 'chart' },
    children: [{
      path: 'production',
      component: () => import('@/views/dataAnalysis/production'),
      meta: { title: '折线图' }
    },
    {
      path: 'health',
      component: () => import('@/views/dataAnalysis/health'),
      meta: { title: '柱状图' }
    },
    {
      path: 'pie',
      component: () => import('@/views/dataAnalysis/pie'),
      meta: { title: '饼图' }
    },
    {
      path: 'scatter',
      component: () => import('@/views/dataAnalysis/scatter'),
      meta: { title: '散点图' }
    },
    {
      path: 'candlestick',
      component: () => import('@/views/dataAnalysis/candlestick'),
      meta: { title: 'K线图' }
    },
    {
      path: 'radar',
      component: () => import('@/views/dataAnalysis/radar'),
      meta: { title: '雷达图' }
    }]
  },
  //css3特效
  {
    path: '/cssThree',
    name: 'cssThree',
    component: Layout,
    meta: { title: 'css3特效', icon: 'star' },
    redirect: '/cssThree/slidebartitle',
    children: [{
      path: 'slidebartitle',
      component: () => import('@/views/cssThree/SlideBarTitle'),
      meta: { title: '幻灯条标题' }
    },
    {
      path: 'scrollText',
      component: () => import('@/views/cssThree/scrollText'),
      meta: { title: '滚动文字' }
    },
    {
      path: 'buttonHoverStroke',
      component: () => import('@/views/cssThree/buttonHoverStroke'),
      meta: { title: '按钮悬停描边' }
    },
    {
      path: 'buttonHoverMultistroke',
      component: () => import('@/views/cssThree/buttonHoverMultistroke'),
      meta: { title: '按钮悬停多重描边' }
    },
    {
      path: 'buttonHoverFlashes',
      component: () => import('@/views/cssThree/buttonHoverFlashes'),
      meta: { title: '按钮悬停闪烁' }
    },
    {
      path: 'dotAnimation',
      component: () => import('@/views/cssThree/dotAnimation'),
      meta: { title: '圆点动画' }
    },
    {
      path: 'snowAnimation',
      component: () => import('@/views/cssThree/snowAnimation'),
      meta: { title: '飘雪动画' }
    },
    {
      path: 'maskEffect',
      component: () => import('@/views/cssThree/maskEffect'),
      meta: { title: '遮罩效果' }
    },
    {
      path: 'todoList',
      component: () => import('@/views/cssThree/todoList'),
      meta: { title: '计划表效果' }
    },
    {
      path: 'particles',
      component: () => import('@/views/cssThree/particles'),
      meta: { title: '粒子特效' }
    },
    {
      path: 'verbatimEffect',
      component: () => import('@/views/cssThree/verbatimEffect'),
      meta: { title: '逐字特效' }
    }]
  },
   //路由嵌套
   {
    path: '/Routers',
    component: Layout,
    hidden: false,
    redirect: '/Routers/Routers1',
    meta: { title: '路由嵌套',icon: 'nested' },
    children: [
      {
        path: 'Router1',
        component: () => import('@/views/Routers/Routers1'),
        meta: { title: '路由1' }
      },
      {
        path: 'Router2',
        component: () => import('@/views/Routers/Routers2'),
        meta: { title: '路由2' }
      }
    ]
  },
  //文章管理
  {
    path: '/blog',
    component: Layout,
    hidden: false,
    meta: { title: '文章管理', icon: '文章' },
    redirect: '/blog/blogList',
    children: [
      {
        path: 'blogList',
        name: 'BlogList',
        component: () => import('@/views/Blog'),
        meta: { title: '博客文章列表' },
        hidden: false
      }
    ]
  },
  // 个人中心
  {
    path: '/user',
    component: Layout,
    meta: { title: '个人中心', icon: 'qq' },
    hidden: false,
    children: [
      {
        path: 'index',
        component: () => import('@/views/user'),
        meta: { title: '个人中心' }
      }
    ]
  },
  //消息提示
  {
    path: '/message',
    name: 'Message',
    component: Layout,
    meta: { title: '消息', icon: 'message' },
    redirect: '/message/msgindex',
    children: [
      {
        path: 'msgindex',
        component: () => import('@/views/Message'),
        meta: { title: '消息提示' }
      }
    ]
  },
  // 标签页
  {
    path: '/tag',
    name: 'Tag',
    component: Layout,
    meta: { title: '标签页', icon: '标签' },
    redirect: '/tag/tagIndex',
    children: [
      {
        path: 'tagIndex',
        component: () => import('@/views/tag'),
        meta: { title: '标签' }
      }
    ]
  },
  // 穿梭框
  {
    path: '/transfer',
    name: 'Transfer',
    component: Layout,
    meta: { title: '穿梭框', icon: 'transfer' },
    redirect: 'transfer/transferIndex',
    children: [
      {
        path: 'transferIndex',
        component: () => import('@/views/Transfer'),
        meta: { title: '穿梭框' }
      }
    ]
  },
  //员工客户管理
  {
    path: '/crm',
    component: Layout,
    hidden: false,
    meta: { title: '员工客户管理', icon: 'people' },
    redirect: '/crm/index',
    children:[{
      path: 'index',
      component: () => import('@/views/crm'),
      meta: { title: '员工管理' }
    },
    {
      path: 'customer',
      hidden: false,
      component: () => import('@/views/crm/customer'),
      meta: { title: '客户管理' }
    },
    {
      path: 'supplier',
      hidden: false,
      component: () => import('@/views/crm/supplier'),
      meta: { title: '供应商管理' }
    }]
  },
  // 后台管理
  {
    path: '/system',
    name: 'system',
    component: Layout,
    redirect: '/system/account',
    meta: { title: '后台管理', icon: 'system' },
    children: [{
      path: 'account',
      component: () => import('@/views/system/account'),
      meta: { title: '账号管理' }
    },
    {
      path: 'role',
      component: () => import('@/views/system/role'),
      meta: { title: '角色管理' }
    },
    {
      path: 'menu',
      component: () => import('@/views/system/menu'),
      meta: { title: '菜单管理' }
    }]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  // mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
  base: '/admin/'
})

const router = createRouter()

// reset 路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher // reset router
}

export default router
